/*
 * This file is part of ksPlatform
 * 
 * Copyright (c) 2014-2015
 * 
 * This file is dual-licensed under the AGPLv3 (http://www.gnu.org/licenses/agpl-3.0.html) 
 * 
 * If you are unsure which license is appropriate for your use, please contact the sales department
 * at 97041437@qq.com.
 */

package cn.com.ksplatform.modules.system.auth.buttonmanager.model;

import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.hibernate.annotations.GenericGenerator;

import com.fasterxml.jackson.annotation.JsonIgnore;

import cn.com.ksplatform.base.BaseModel;
import cn.com.ksplatform.modules.system.auth.rolemanager.model.PlatRole;

/**
 * @ClassName:PlatButton <br/>
 * @deprecated:TODO. <br/>
 * @Date: 2015年5月21日 下午5:10:17 <br/>
 * 
 * @author Mr.Luoxing
 * @version 1.0
 */
@Entity
@Table(name = "t_sys_button")
public class PlatButton extends BaseModel implements Comparable<PlatButton>{
	@Id
	@GenericGenerator(name = "systemUUID", strategy = "uuid")
	@GeneratedValue(generator = "systemUUID")
	@Column(name = "btnId")
	private String btnId;
	private String btnName;
	private String icon;
	private String enabled;
	private String btnEvent;

	@JsonIgnore
	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "btnGId")
	private PlatButtonGroup btnGroup;

	@JsonIgnore
	@ManyToMany(fetch = FetchType.LAZY, cascade = { CascadeType.REMOVE })
	@JoinTable(name = "t_sys_button_role", joinColumns = @JoinColumn(name = "btnId"), inverseJoinColumns = @JoinColumn(name = "roleId"))
	private Set<PlatRole> roles;

	public String getBtnId() {
		return btnId;
	}

	public void setBtnId(String btnId) {
		this.btnId = btnId;
	}

	public String getBtnName() {
		return btnName;
	}

	public void setBtnName(String btnName) {
		this.btnName = btnName;
	}

	public String getIcon() {
		return icon;
	}

	public void setIcon(String icon) {
		this.icon = icon;
	}

	public String getEnabled() {
		return enabled;
	}

	public void setEnabled(String enabled) {
		this.enabled = enabled;
	}

	public Set<PlatRole> getRoles() {
		return roles;
	}

	public void setRoles(Set<PlatRole> roles) {
		this.roles = roles;
	}

	public PlatButtonGroup getBtnGroup() {
		return btnGroup;
	}

	public void setBtnGroup(PlatButtonGroup btnGroup) {
		this.btnGroup = btnGroup;
	}

	public String getBtnEvent() {
		return btnEvent;
	}

	public void setBtnEvent(String btnEvent) {
		this.btnEvent = btnEvent;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((btnId == null) ? 0 : btnId.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		PlatButton other = (PlatButton) obj;
		if (btnId == null) {
			if (other.btnId != null)
				return false;
		} else if (!btnId.equals(other.btnId))
			return false;
		return true;
	}

	@Override
	public int compareTo(PlatButton arg0) {
		return this.getBtnId().compareTo(arg0.getBtnId());
	}

}
